home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / timerh.com / TIMERH.DOC < prev    next >
Encoding:
Text File  |  1990-01-15  |  10.9 KB  |  384 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.                               HIGH PRECISION TIMER
  21.                                   DOCUMENTATION
  22.  
  23.                                    Version 5.5
  24.                                 January 14, 1990
  25.  
  26.  
  27.                                   Public Domain
  28.                           by Eagle Performance Software
  29.  
  30.  
  31.  
  32.    TIMERH High Precision Timer                      Documentation, Version 5.5
  33.  
  34.  
  35.  
  36.                        T A B L E   O F   C O N T E N T S
  37.  
  38.              Features .  . . . . . . . . . . . . . . . . . . . . . 3
  39.              Distribution Files  . . . . . . . . . . . . . . . . . 3
  40.              Demonstration . . . . . . . . . . . . . . . . . . . . 3
  41.              Simple Programming  . . . . . . . . . . . . . . . . . 3
  42.              How It Works  . . . . . . . . . . . . . . . . . . . . 4
  43.              Support . . . . . . . . . . . . . . . . . . . . . . . 5
  44.              Reference . . . . . . . . . . . . . . . . . . . . . . 5
  45.              Revisions . . . . . . . . . . . . . . . . . . . . . . 6
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.                                        2
  93.    TIMERH High Precision Timer                      Documentation, Version 5.5
  94.  
  95.  
  96.    FEATURES
  97.  
  98.    This high precision timer written in Pascal allows you to time events or 
  99.    programs with 1 micro-second resolution up to 24 hours.  The program 
  100.    simply uses the extended resolution of the Intel 8253/8254 timer chip 
  101.    which is the same chip that generates an interrupt for the system timer 
  102.    (every 1/18.2... seconds).
  103.  
  104.    Compatibility - TIMERH works on all IBM PC, XT, AT, PS/2, and 3270 PC 
  105.    compatible computers.  The source code can be compiled with either Turbo 
  106.    Pascal 5.0, 5.5, or QuickPascal.
  107.  
  108.  
  109.    DISTRIBUTION FILES
  110.  
  111.    In this version, TIMERH55.ARC contains:
  112.  
  113.      TimerH  .pas:  Timer unit source code.
  114.      TimerH  .doc:  This file.
  115.      TimeDemo.arc:  Demonstration file to show elapsed time.
  116.  
  117.  
  118.    DEMONSTRATION
  119.  
  120.    To get a feeling of the timer, let's run the demonstration program that 
  121.    came with the utility.  Do the following steps:
  122.  
  123.      1. Make and run TIMEDEMO.PAS.
  124.      2. Press RETURN for elapsed time since the beginning of the 
  125.         program.
  126.      3. Press ESC to quit the program.
  127.  
  128.  
  129.    SIMPLE PROGRAMMING
  130.  
  131.    Basically, to time a given event in your program, the source code should 
  132.    look like the following:
  133.  
  134.      ...
  135.      begin
  136.        ...
  137.        Timer (Sync);   { Optional one time use }
  138.        Timer (Start);
  139.        ...
  140.        { Code to be tested goes here. }
  141.        ...
  142.        Timer (Stop);
  143.        ...
  144.      end.
  145.  
  146.    Start - Timer(Start) resets the initial starting value of T1 so that all 
  147.    subsequent splits will be referenced to this point in time.  You can use 
  148.    this more that once.
  149.  
  150.    Stop - Timer(Stop) takes a split in reference to the last Timer(Start) 
  151.  
  152.  
  153.    TIMERH High Precision Timer                                         Page 3
  154.    TIMERH High Precision Timer                      Documentation, Version 5.5
  155.  
  156.  
  157.    which changes the value of T2.  Subsequent uses of Timer(Stop) are 
  158.    permitted, but there is a little overhead for its execution that is not 
  159.    accounted.
  160.  
  161.    Sync - Timer(Sync), placed just before the first start, resets the timer at 
  162.    a zero count.  It is recommended that you use the default Sync parameter 
  163.    for consistent results.  The Sync parameter starts the chip timer zero.  
  164.    This puts the next interrupt (which uses about 15-200 microseconds to 
  165.    update the system timer) at 1/18.2 seconds away.  This makes quick events 
  166.    (<1/18.2 seconds) uninterrupted.  Since the system timer is independent of 
  167.    the real time clock, it doesn't affect the time of day on your computer.
  168.  
  169.    Overhead - The overhead for the elapsed time between the start and stop is 
  170.    kept in the value T0.  The global value ElapsedTime excludes the overhead 
  171.    after Timer(Stop).
  172.  
  173.    Jitter - Most events will be within plus or minus 3 microseconds depending 
  174.    on your CPU.
  175.  
  176.  
  177.    HOW IT WORKS
  178.  
  179.    To work both on IBM PC which use the 8253 chip and on the IBM AT using the 
  180.    8254 chip, it is necessary to use  the common characteristics of both  
  181.    chips:
  182.  
  183.      1. The output port to the timer for counter 0 which is a utility counter  
  184.         is $43 and the input port is $40.  The latch code is $00 to read a 
  185.         value from the chip.
  186.  
  187.      2. The system timer is a four-byte value and updated in memory at 
  188.         0040h:006Ch, but only the first three bytes (21 bits) are used because 
  189.         it only counts up to 1573040 (1800AFh) ticks per day.  At that 
  190.         resolution, it only amounts to:
  191.  
  192.           1573040/(60*60*24) = 18.206481481 ticks/sec
  193.  
  194.      3. The chip counts down from $0000 negatively until it wraps to zero 
  195.         again which then sends the usual interrupt every 1/18.2... seconds to 
  196.         update the system timer in the BIOS data area.
  197.  
  198.      4. Using the chip ports, we can access and lock on to the count down 
  199.         timer and get a value.  Since it has one full word in the count, the 
  200.         total extended resolution of 16 bits is:
  201.  
  202.           1573040 * 2^16 = 103090749440 ticks/day
  203.                          = 1193179.9704 ticks/sec
  204.  
  205.      5. This total resolution requires a five-byte value to hold the 37 bit 
  206.         number.  If two days are needed in the calculation which is required 
  207.         when passing midnight, a 38 bit value will be needed, but notice that 
  208.         it never reaches the full 40 bits of five bytes.  This means that 
  209.         6 byte reals are fully capable of handling the value with no loss in 
  210.         resolution.
  211.  
  212.  
  213.  
  214.    TIMERH High Precision Timer                                         Page 4
  215.    TIMERH High Precision Timer                      Documentation, Version 5.5
  216.  
  217.  
  218.      6. Interrupt control while taking splits was a problem.  Since the chip 
  219.         and CPU are independent, it is possible that the chip may try to send 
  220.         an interrupt on the bus just as the OUT code is being executed.  The 
  221.         chip will read 0-2 microseconds, but the DOS timer will be one tick 
  222.         short.  An easy solution is to take two readings of the DOS timer low 
  223.         byte and see if they differ - one before the chip is latched and 
  224.         another after.  If they differ, an extra tick is needed for the system 
  225.         timer part of the split only the timer value is small enough (<10000 
  226.         microseconds) to confirm that the interrupt did occur.
  227.  
  228.      7. It is also important that no conditional statements are used in the 
  229.         code so that the overhead is constant.
  230.  
  231.      8. The wake up mode of all timer chips is mode 3, but there is no way to 
  232.         use mode 3 on the 8253 with software.  The 8254 chip made mode 3 
  233.         superior with access to its status register, but software accessing 
  234.         this register is incompatible with the IBM PC.  So, TIMERH initializes 
  235.         with the common mode 2.  When the program is terminated, it is 
  236.         restored back to mode 3 in case anything else may expect the default 
  237.         mode.
  238.  
  239.  
  240.    SUPPORT
  241.  
  242.    If you have questions, comments, or suggestions, the Eagle can be contacted 
  243.    by four means - (1) CompuServe, (2) telephone, (3) The Eagle BBS, or 
  244.    (4) mail.
  245.  
  246.    CompuServe - The most dependable way to contact the Eagle is through 
  247.    CompuServe.  James (Jim) H. LeMay has written the Pascal version of TIMERH, 
  248.    but the person to contact is Jordan Gallagher who can be contacted on the 
  249.    Borland Forum by typing GO BPROGA from the CompuServe main menu.  You will 
  250.    enter the Forum for Turbo Pascal.  You can contact Jordan with his PPN 
  251.    number of 73557,2342.  Messages can also be left through EasyPlex.
  252.  
  253.    Telephone - Jordan can also be reached by phone at (214) 539-7855 on 
  254.    weekdays and Saturday from 9:00 a.m. to 8:00 p.m CST.
  255.  
  256.    The Eagle BBS - You can also contact us on our 24-hour BBS at (214) 539-
  257.    9878, 1200/2400 N81.
  258.  
  259.    Mail - For problems, please write:
  260.  
  261.        Eagle Performance Software
  262.        P.O. Box 292786
  263.        Lewisville, TX  75029-2786
  264.  
  265.  
  266.    REFERENCE
  267.  
  268.    For more information on the Intel 8253/8254 timer chips, refer to the Intel 
  269.    Microsystem Component Handbook, vol 2.  You can also call Intel literature 
  270.    sales at 1-800-548-4725.
  271.  
  272.  
  273.  
  274.  
  275.    TIMERH High Precision Timer                                         Page 5
  276.    TIMERH High Precision Timer                      Documentation, Version 5.5
  277.  
  278.  
  279.    REVISIONS
  280.  
  281.    Version 5.5 (01-15-90):
  282.       Original release.
  283.  
  284.  
  285.  
  286.  
  287.  
  288.  
  289.  
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.    TIMERH High Precision Timer                                         Page 6
  337.  
  338.          ----------------end-of-author's-documentation---------------
  339.  
  340.                          Software Library Information:
  341.  
  342.                     This disk copy provided as a service of
  343.  
  344.                            Public (software) Library
  345.  
  346.          We are not the authors of this program, nor are we associated
  347.          with the author in any way other than as a distributor of the
  348.          program in accordance with the author's terms of distribution.
  349.  
  350.          Please direct shareware payments and specific questions about
  351.          this program to the author of the program, whose name appears
  352.          elsewhere in  this documentation. If you have trouble getting
  353.          in touch with the author,  we will do whatever we can to help
  354.          you with your questions. All programs have been tested and do
  355.          run.  To report problems,  please use the form that is in the
  356.          file PROBLEM.DOC on many of our disks or in other written for-
  357.          mat with screen printouts, if possible.  PsL cannot debug pro-
  358.          programs over the telephone, though we can answer questions.
  359.  
  360.          Disks in the PsL are updated  monthly,  so if you did not get
  361.          this disk directly from the PsL, you should be aware that the
  362.          files in this set may no longer be the current versions. Also,
  363.          if you got this disk from another vendor and are having prob-
  364.          lems,  be aware that  some files may have become corrupted or
  365.          lost by that vendor. Get a current, working disk from PsL.
  366.  
  367.          For a copy of the latest monthly software library newsletter
  368.          and a list of the 2,000+ disks in the library, call or write
  369.  
  370.                            Public (software) Library
  371.                                P.O.Box 35705 - F
  372.                             Houston, TX 77235-5705
  373.  
  374.                                 1-800-2424-PSL
  375.                                  MC/Visa/AmEx
  376.  
  377.                           Outside of U.S. or in Texas
  378.                           or for general information,
  379.                               Call 1-713-524-6394
  380.  
  381.                           PsL also has an outstanding
  382.                           catalog for the Macintosh.
  383.  
  384.